主题
加密模型包到文件 - YoloEncryptModel
函数简介
将明文模型与可选类别名表打成欧拉加密包并写入磁盘;包头写入 modelType、inferenceType。
接口名称
YoloEncryptModelDLL 调用
int YoloEncryptModel(long ola, string modelPath, string ncnnParamPath, string namesLabel, string password, int modelType, int inferenceType, string savePath);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug 对象指针,由 CreateCOLAPlugInterFace 生成。 |
| modelPath | 字符串 | 主模型路径。 |
| ncnnParamPath | 字符串 | NCNN .param,可空。 |
| namesLabel | 字符串 | 类别名称:可选。文件路径或内联 |/多行文本;编码自动识别。详见 类别名称表说明 |
| password | 字符串 | 加密密码。 |
| modelType | 整数型 | 模型后端类型,见下表。 |
| inferenceType | 整数型 | 推理任务类型,见下表。 |
| savePath | 字符串 | 输出加密包路径。 |
示例
以下示例以 ONNX 单文件 加密为目标检测包:ncnnParamPath 传空,modelType=1,inferenceType=0。NCNN 需额外传入 .param 且 modelType=2。
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");csharp
using OLAPlug;
var ola = new OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
@"models\yolov8n.onnx", "", @"models\coco.names",
"pwd", 1, 0, @"models\yolov8n.olam");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret := ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
let ret = ola.yolo_encrypt_model(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");cpp
var ola = com("OlaPlug.OlaSoft")
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
var ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel("models/yolov8n.onnx", "", "models/coco.names", "pwd", 1, 0, "models/yolov8n.olam")text
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型
ola.创建 ()
' ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
ret = ola.YoloEncryptModel (“models/yolov8n.onnx”, “”, “models/coco.names”, “pwd”, 1, 0, “models/yolov8n.olam”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
var ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
整数 ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// ONNX:ncnnParamPath 传空;modelType=1(ONNX),inferenceType=0(Detect)
int ret = ola.YoloEncryptModel(
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
YoloEncryptModel(instance,
"models/yolov8n.onnx", "", "models/coco.names",
"pwd", 1, 0, "models/yolov8n.olam");csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int YoloEncryptModel(long ola, string modelPath, string ncnnParamPath,
string namesLabel, string password, int modelType, int inferenceType, string savePath);
long instance = CreateCOLAPlugInterFace();
YoloEncryptModel(instance,
@"models\yolov8n.onnx", "", @"models\coco.names",
"pwd", 1, 0, @"models\yolov8n.olam");python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.YoloEncryptModel.restype = c_int
instance = ola.CreateCOLAPlugInterFace()
ola.YoloEncryptModel(
instance,
b"models/yolov8n.onnx", b"", b"models/coco.names",
b"pwd", 1, 0, b"models/yolov8n.olam")返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
| 负数 | 失败;绝对值为错误码。与 GetLastError() 一致。 |
完整错误码表见 YOLO 错误码说明。
注意事项
| 项目 | 说明 |
|---|---|
| 模块权限 | 需要插件已开通 YOLO 模块权限(Reg、Login的FeatureList中包含YOLO特性)。 |
| 路径 | namesLabel 支持文件路径、内联 ` |
modelType 模型后端类型
| 值 | 含义 |
|---|---|
| 0 | TensorRT Engine(.engine) |
| 1 | ONNX(.onnx) |
| 2 | NCNN(.bin + .param 双文件) |
inferenceType 推理任务类型
| 值 | 含义 |
|---|---|
| 0 | Detect 目标检测 |
| 1 | Classify 图像分类 |
| 2 | Segment 实例分割 |
| 3 | Pose 姿态估计 |
| 4 | Obb 旋转框检测 |
